package com.greenhouse.mapper.greenhouse;

import com.greenhouse.model.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    //查询user表的账户数量
    @Select("select count(*) from users")
    int getUserCount();
    //查询users表中用户最大的Id
    @Select("select max(id) from users")
    Integer getMaxId();
    //根据用户账号查询用户
    User findByUsername(String username);
    //通过id查询用户
    User findById(Integer id);
    //注销账户
    @Delete("delete from users where id = #{id}")
    int deleteUser(Integer id);
    //注册账号
    @Insert("insert into users (username,password,role,name,create_time) values (#{username}, #{password},#{role} ,#{name}, NOW())")
    int insertUser(User u);

    //修改密码
    @Update("update users set password = #{password} where id = #{id}")
    int updatePassword(String password,Integer id);
    //修改头像
    @Update("update users set head_img_url = #{headImgUrl} where id = #{id}")
    int updateHeadImg(String headImgUrl,Integer id);
    //修改名称
    @Update("update users set name = #{name} where id = #{id}")
    int updateName(String name,Integer id);
    //修改邮箱
    @Update("update users set email = #{email} where id = #{id}")
    int updateEmail(String email, Integer id);
}
